import logging
import os

from llama_index.core import SummaryIndex, SimpleDirectoryReader
from llama_index.llms.dashscope import DashScope

logging.basicConfig(level=logging.DEBUG)
data_dir = 'D:/pythonRoom/llm_llama/data'

print('初始化模型对象')
llm = DashScope(
    model="qwen-turbo",  # 使用通义千问Max模型 qwen-max
    api_key=os.getenv("DASHSCOPE_API_KEY"),  # 从阿里云控制台获取
    temperature=0.3
)

documents = SimpleDirectoryReader(data_dir).load_data()

summary_index = SummaryIndex.from_documents(documents)

qe = summary_index.as_query_engine(llm=llm)

prompts = qe.get_prompts()

for k, p in prompts.items():
    print('===========================')
    print(f"Prompt Key: {k}")
    print("Text:")
    print(p.get_template())
    print("\n")
